﻿using System;
using System.Collections.Generic;
using System.IO;

namespace SearchAlgorithms.Services
{
    public class FileReadBlock
    {
        private string _filePath;
        private int _bufferSize;

        public Action<byte[]> DataArrived;

        public FileReadBlock(string filePath, int bufferSize)
        {
            _filePath = filePath;
            _bufferSize = bufferSize;
        }

        public void ReadBytes()
        {
            byte[] buffer = new byte[_bufferSize];
            using (var _fs = File.OpenRead(_filePath))
            {
                while (true)
                {
                    int len = _fs.Read(buffer, 0, _bufferSize);
                    if (len == 0)
                    {
                        break;
                    }
                    DataArrived?.Invoke(buffer[..len]);
                }
            }
        }
    }
}

